*********************************************************************************
/*   Event Study showing Audit Probability Decline Following Audit	*/
*********************************************************************************
* Set directories 

adopath + "${oi_home}/Research files/ado"

* File paths
local datapath "${mvpf_audits}/data/cleaned" 
local datafolder "${mvpf_audits}/data/outside" 
local graphpath "${graphpath}" 

* Version of fig to produce 
global version  ${version} // paper or slides

* Other formatting
if "${version}" == "slides" {
	global title "title(" ", size(vhuge))"
	global img wmf
	graph set window fontface "Arial"
	global title "title(" ", size(vhuge))"
	global axis_size "" //xsize(6.5) ysize(4)" // makes figure wider
}

else if "${version}" == "paper" {
	global title "title("")"
	global img pdf
	graph set window fontface "LMRoman10-Regular"
	global title " "
	global axis_size " " // makes figure wider
}

* Import data
import delimited "`datafolder'/d_zret.txt", clear varnames(1)
drop if auditindicator == .

rename v3 se
split v1, p("=") g(nrp)
drop v1 nrp1

split nrp2, p(" # ") g(treat)
drop nrp2 treat2
destring treat1, replace

gen auditind_treat = .
forvalues r = 87(1)114 {
	
	qui sum auditindicator if treat1 == `r' & nrp3 == "1"
	replace auditind_treat = `r(mean)' if treat1 == `r' & nrp3 == ""
}

gen index = _n
qui sum index
qui sum auditindicator if index == `r(max)'
local control = `r(mean)'

drop if index > 28
gen ratio = auditind_treat / (auditindicator + `control')
gen ratio_capped = ratio
replace ratio_capped = 0.52 if ratio > 0.5

g event = index-14

drop if abs(event) >= 13
*
if "${version}"=="paper"{
	twoway  (scatter ratio_capped event if event != 0 & event != 1, mc(gs4) ms(O)) ///
			(line ratio_capped event if event < 0, lc(gs4)) ///
			(line ratio_capped event if event > 1, lc(gs4)) ///
			, ///
			xline(-2, lw(vthin) lc(gs11)) ///
			xline(2, lw(vthin) lc(gs11)) ///
			yline(0, lw(vthin) lp(dash) lc(gs11)) ///
			xtitle("Year relative to tax year of audited return") ///
			ytitle("Audit Probability") ///
			xlabel(-12(2)12 , nogrid)  ///
			ylab(-0.2(0.2)0.4, nogrid format(%5.1fc))  ///
			yscale(r(-0.3 0.5))  ///
			legend(off) ///
			${title} ${axis_size}	
graph export "`graphpath'/future_audit_probability.wmf", as(wmf) replace
}
